from lxml import etree

xml = """
    <book>
        <id>1</id>
        <name>野花遍地香</name>
        <price>1.23</price>
        <nick>臭豆腐</nick>
        <author>
            <nick id="10086">周大强</nick>
            <nick id="10010">周芷若</nick>
            <nick class="jay">周杰伦</nick>
            <nick class="jolin">蔡依林</nick>
            <div>
                <nick>惹了</nick>
            </div>
        </author>
        <partner>
            <nick id="ppc">胖胖陈</nick>
            <nick id="ppbc">胖胖不陈</nick>
        </partner>
    </book>
    """
et = etree.XML(xml)
# result = et.xpath('/book') # /表示根节点
# result = et.xpath('/book/name/text()')[0] # text() 拿文本
# result = et.xpath('/book//nick')  # //表示所有的子孙后代
# result = et.xpath('/book/*/nick/text()')  # * 代表谁都行
# result = et.xpath("/book/author/nick[@class='jay']/text()")  # [] 表示筛选， @属性名=值
result = et.xpath("/book/partner/nick/@id")  # 最后一个 / 表示拿到nick里面的id的内容，@属性值 可以直接拿到属性值
print(result)

